home *** CD-ROM | disk | FTP | other *** search
- /*
- ffs.c - find first set bit
- Carmine T. Guida
- 7 - 7 - 93 Public Domain
- */
-
- #include <support.h>
-
- int
- ffs(bits)
- int bits;
- {
- register int i;
-
- if (!bits)
- return 0;
-
- i = 1;
-
- #ifndef __MSHORT__
- if (!(bits & 0x0000FFFF)) /* Check word */
- {
- bits >>= 16;
- i += 16;
- }
- #endif
-
- if (!(bits & 0x00FF)) /* Check byte */
- {
- bits >>= 8;
- i += 8;
- }
- if (!(bits & 0x0F)) /* Check nybble */
- {
- bits >>= 4;
- i += 4;
- }
- if (!(bits & 0x3)) /* Check 2 bits */
- {
- bits >>= 2;
- i += 2;
- }
- if (!(bits & 0x1)) /* Check bit */
- i += 1;
-
- return i;
- }
-